The function pivot_longer() longifys data, converting it from wide to long. Long data is generally the preferred format for Tidyverse, and is especially useful for ggplot2.
When data is longified:
The number of rows increases.
The number of columns decreases.
To longify data a set of columns are chosen.
The column names are assigned as data of a names column.
The values within the columns are assigned to a value column. Each value is within its own row.
For demonstration we’ll load the fisheries_wide_tbl data from the mgrtibbles package (hyperlink includes install instructions).
#Load packagelibrary("mgrtibbles")#fisheries_wide_tbl tibble for demonstrationmgrtibbles::fisheries_wide_tbl |>#View first 11 columns with select dplyr::select(1:11)